/*! \file
 * \brief Implementation file for the MythFile library.
 * \author Ivo Wingelaar
 * \date 2011
 * \version 0.1.0
 * \copyright GNU Lesser General Public License v3
 */

#include "MythFile.hpp"
#include "MythFile_InputFile_C.hpp"
#include "MythFile_OutputFile_C.hpp"

namespace Myth
{
namespace File
{

//! Creates an input from a file.
/*!
 * \return A pointer to an input from a file.
 * \param[in] stream_name Name of the stream.
 * \param[in] file_name Path to the file you want to open for reading.
 */
_MYTH_FILE_API_ Stream::Input* _MYTH_CALL_CONV_ create_input_file(const std::string& stream_name, const std::string& file_name)
{
    InputFile_C* temp = new InputFile_C(stream_name, file_name);

    if(temp->is_open())
        return temp;
    else
        temp->decrement_counter();
    return 0;
}

//! Creates an output to a file.
/*!
 * \return A pointer to an output to a file.
 * \param[in] stream_name Name of the stream.
 * \param[in] file_name Path to the file you want to open for writing.
 * \param[in] append If true and the file already exists, any data written will be appended to it, otherwise it will create a new file.
 */
_MYTH_FILE_API_ Stream::Output* _MYTH_CALL_CONV_ create_output_file(const std::string& stream_name, const std::string& file_name, bool append)
{
    OutputFile_C* temp = new OutputFile_C(stream_name, file_name, append);

    if(temp->is_open())
        return temp;
    else
        temp->decrement_counter();
    return 0;
}

////////////////////////////////////////////////////////////////////////////
//! Returns the version of the MythFile library.
_MYTH_FILE_API_ uint32_t _MYTH_CALL_CONV_ get_myth_file_version(void)
{
    return MYTH_SDK_VERSION;
}

} // namespace File
} // namespace Myth
